package com.xiyuan.smartutils.function;

import com.xiyuan.smartutils.lambda.Lambda;

/**
 * 继承 Function
 *
 * @author xiyuan-lgz 2023-02-15 @version v1.0.0 新建与整理
 */
@FunctionalInterface
public interface SFunc3<P, P1, P2, R> extends Lambda {
    R apply(P t1, P1 t2, P2 t3) throws Exception;
    
    /**
     * 忽略异常，返回null
     *
     * @return
     */
    default R callNoThrow(P t1, P1 t2, P2 t3) {
        try {
            return apply(t1, t2, t3);
        }
        catch (Exception e) {
            return null;
        }
    }
    
    default R callWithRuntimeException(P t1, P1 t2, P2 t3) {
        try {
            return apply(t1, t2, t3);
        }
        catch (RuntimeException e) {
            throw e;
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
